package com.zhuss.team.processor;

import com.zhuss.bean.bo.team.invest.CreateInvestBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.team.db.dao.ext.InvestDao;
import com.zhuss.team.db.entity.Invest;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/26 13:25
 */
@Component("investCreate")
public class InvestCreate extends AbstractProcessor<Object, CreateInvestBo> implements Processor<Object, CreateInvestBo> {

    @Autowired
    private InvestDao investDao;

    @Override
    public Object process(CreateInvestBo bo) throws WpsException {
        Invest invest = new Invest();
        invest.setInvestName(bo.getInvestName());
        invest.setInvestGroup(bo.getInvestGroup());
        invest.setSort(bo.getSort());
        invest.setArea(bo.getArea());

        invest.setCreator(bo.getConcurrentUserName());
        invest.setCreatorId(bo.getConcurrentUserId());
        invest.setCreateTime(new Date());
        investDao.create(invest);
        return null;
    }

    @Override
    public Object log(CreateInvestBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.协同发布.key());
        record.setAction(LogActionEnum.问卷创建.key());
        record.setTargetId(param.getTargetId());
        record.setTargetName(param.getInvestName());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(CreateInvestBo createInvestBo) throws WpsException {

    }
}
